package day2;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

public class Test7_kafka {
    public static void main(String[] args) throws Exception {
        // flink 消费kafka中的数据

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers","hadoop10:9092");
        properties.setProperty("group.id","test");

        DataStreamSource<String> ds = env.addSource(new FlinkKafkaConsumer<>("topic1", new SimpleStringSchema(), properties));

       /* SingleOutputStreamOperator<String> ds2 = ds.filter(new FilterFunction<String>() {
            @Override
            public boolean filter(String s) throws Exception {
                String flag = s.split(",")[1];
                if ("success".equals(flag)) {
                    return true;
                }
                return false;
            }
        });*/

        ds.print();
        env.execute();
    }
}
